﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using NHibernate;
using NHibernate.Cfg;
using NHibernate.Tool;

using FluentNHibernate.Cfg;
using FluentNHibernate;
using FluentNHibernate.Cfg.Db;
using NHibernate.Tool.hbm2ddl;

using NHibernate.Linq;

namespace TCEasyPrintRev.Controllers
{
    class CRUD<T>
    {

        public static  void insert(T kelas)
        {
            var factory = NHibernateHelper.GetSessionFactory();
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var category = kelas;
                    session.Save(category);
                    transaction.Commit();
                }
            }
        }

        public static void update(T kelas)
        {
            var factory = NHibernateHelper.GetSessionFactory();
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var category = kelas;
                    session.SaveOrUpdate(kelas);
                    transaction.Commit();
                }
            }
        }

        public static void delete(T kelas)
        {
            var factory = NHibernateHelper.GetSessionFactory();
            using (var session = factory.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var category = kelas;
                    session.Delete(kelas);
                    transaction.Commit();
                }
            }
        }



      public  static ISessionFactory load()
        {
            var factory = NHibernateHelper.GetSessionFactory();
            return factory;
        }
    }
}

